package ACwing.P3SearchandGraph.DFS;

import java.util.Scanner;

/**
 * @Date : 2023-04-02
 * @Description:842. 排列数字
 * 输出全排列
 */
public class ArrangeNumbers {
    static int N=10;
    static int n;
    static int []path=new int[N];
    static boolean[] s=new boolean[N];//这个位置是否放过数字了
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        n= scanner.nextInt();
        dfs(0);
    }
    static void dfs(int u){
        if(u==n){//枚举完了
            for (int i = 0; i < n; i++)
                System.out.print(path[i]+" ");
            System.out.println();
            return;
        }
            for (int i = 1; i <= n; i++) {
                if(!s[i]){//没有放过
                    path[u]=i;
                    s[i]=true;
                    dfs(u+1);
                    s[i]=false;
                }
            }

        }
    }

